/*** Class Name: ifulfillNotesBatch 
* Author: Accenture      
* Requirement/Project Name: iFULFILL
* Requirement/Project Description:SFDC should verify that the CSS system is not down prior to sending an Notes outbound message.
* This batch will process all the Failed Notes records where status code not equal to '0' .
* 
* **/
global class ifulfillNotesBatch implements Schedulable{
   
    ID ifulfillNoteRecordTypeID = RecordTypeHelper.GetRecordTypeIdByDevName('Notes__c',  'ifulfill_Manual_Notes');
    global void execute(SchedulableContext sc) {
        ifulfillNotesRestAPIBatch  notes= new ifulfillNotesRestAPIBatch(); 
        notes.query='select Id,CreatedByID,Fullfilment_Notes__c,LastModifiedDate,Notes__c,Status_Code__c,Delivery_Status__c,Error_Stack__c,Error_Message__c from Notes__c  where (Status_Code__c !=null or Status_Code__c!=\'\') and Status_Code__c!=\'0\' and recordtypeid =\''+ifulfillNoteRecordTypeID+'\' limit 400';
        ID batchprocessid = Database.executeBatch(notes,1);
      
    }  
    
     /* test class for classes/triggers */
 
  static testMethod void testifulfillNotesBatch () 
  {
      
      
        ID ifulfillNoteRecordTypeID = RecordTypeHelper.GetRecordTypeIdByDevName('Notes__c',  'ifulfill_Manual_Notes');
        test.starttest();
        Fullfilment_Item__c fi = new Fullfilment_Item__c(   Main_Listing_Phone_Number__c = '100',Listed_Name__c ='XYZ',Heading_Name__c ='Heading name',Item_Id__c = 'Item id' ,Product_Code__c ='p1',UDAC__c ='Udac1',Region__c = 'region1',Transaction_Type__c ='New');
        insert fi;
        Notes__c  note  = new Notes__c ( Fullfilment_Notes__c = fi.id ,Status_Code__c = '1', Error_Stack__c= 'Unable to contact CSS.PleaFailed', Error_Message__c= 'Unable to contac', recordtypeid =ifulfillNoteRecordTypeID);
         insert note;
        ifulfillNotesRestAPIBatch  notes= new ifulfillNotesRestAPIBatch(); 
        notes.query='select Id,CreatedByID,Fullfilment_Notes__c,LastModifiedDate,Notes__c,Status_Code__c,Delivery_Status__c,Error_Stack__c,Error_Message__c from Notes__c  where (Status_Code__c !=null or Status_Code__c!=\'\') and Status_Code__c!=\'0\' and recordtypeid =\''+ifulfillNoteRecordTypeID+'\' limit 400';
        ID batchprocessid = Database.executeBatch(notes,1);
        
        ifulfillNotesBatch trackHist = new ifulfillNotesBatch ();
        String sch = '0 0 23 * * ?';
        system.schedule('Ifulfill', sch , trackHist );
        test.stopTest();
  }           
    
}